<?php

function restaurant_restaurant_delete_confirm($restaurant){
     return '<a href="'.url('/restaurant/etterem_delete/'.$restaurant->rid).'" onClick="return confirm(\'Biztosan törli az éttermet?\');">'.t('Törlés').'</a>';
}


function restaurant_restaurant_delete($rid){
    db_delete('ep_restaurants')
        ->condition('rid', $rid)
        ->execute();
    drupal_set_message('Étterem sikeresen törölve.');
    drupal_goto('restaurant/etterem_list');
}


function restaurant_restaurant_list_page(){
        global $user;
        $header = array(
	array('data' => 'Étterem neve:', 'field' => 'name', 'sort' => 'asc'),
	array('data' => 'Város', 'field' => 'city'),
	array('data' => 'Website', 'field' => 'website'),
        array('data' => 'Telefon', 'field' => 'telephone'),
        array('data' => 'Nyitvatartás', 'field' => 'open'),
        array('data' => 'Házhozszállítás', 'field' => 'delivery'),
        array('data' => 'Wifi', 'field' => 'wifi'),
        array('data' => 'Parkolás', 'field' => 'parking'),
        t('Törlés'),
        t('Szerkesztés')
            
	);        
        $query = db_select('ep_restaurants','r')
                ->extend('TableSort')
                    ->orderByHeader($header)
                ->fields('r', array(
                    'rid',
                    'name',
                    'city',
                    'website',
                    'telephone',
                    'open',
                    'delivery',
                    'wifi',
                    'parking'
                ));
        $query -> condition('uid',$user->uid,'=');
                
        $results = $query
                    ->execute();

        $rows = array();	
        foreach ($results as $restaurant) {
	$rows[] = array(
			'data' => array(
                            $restaurant->name,
                            $restaurant->city,
                            $restaurant->website,
                            $restaurant->telephone,
                            $restaurant->open,
                            $restaurant->delivery?t('igen'):t('nem'),
                            $restaurant->wifi?t('igen'):t('nem'),
                            $restaurant->parking?t('igen'):t('nem'),
                            restaurant_restaurant_delete_confirm($restaurant),
                            l('Szerkesztés','/restaurant/restaurant_edit'.'/'.$restaurant->rid)
                            ),                    
        );
        }	

        $html = theme('table', 
			array(
				'header' => $header,
				'rows'=>$rows,
				'sticky' => TRUE,		
				'empty' => t('Nincs elem ebben a listában...'),
			)
		);
        
        $html .= theme('pager',
                array('tags' => array())
        );     
        
        return $html;
}



